Skip to content

Speed up spring-boot-server-tests #25457

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

dreis2211
Copy link
Contributor

Hi,

this PR improves the build time of spring-boot-server-tests by applying some caching in certain places. Specifically:

  • A cache for the ApplicationBuilders, which avoids packaging the JAR (or WAR) for each test invocation. With the cache the packaging now only run once per container and packaging method (e.g. Tomcat & JAR or Undertow & WAR)
  • A cache for the AbstractApplicationLauncher, which pretty much follows the same idea as the tests don't need to start the application for each test invocation, but rather only once per container, packaging & launcher combination.

The second cache is a bit more aggressive and has the implication that the started processes can only be killed after all tests are run. Unfortunately, I found no way to make this a little cleaner in JUnit 5 as the TestTemplateInvocationContext(Provider) mechanism only works on the single test invocation level. The same applies to the exposed additional extensions in those contexts, which the AbstractApplicationLauncher is.

On my local machine the new approach reduces the time for testing from almost 8 minutes to roughly 1:30-2 minutes. The bigger part of this comes from the launcher cache, because we don't have to pay the 3-4 second application startup time hit on every test invocation.

Let me know what you think.
Cheers,
Christoph

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Feb 27, 2021
@wilkinsona wilkinsona added this to the 2.3.x milestone Mar 1, 2021
@wilkinsona wilkinsona added type: task A general task and removed status: waiting-for-triage An issue we've not yet triaged labels Mar 1, 2021
wilkinsona pushed a commit that referenced this pull request Mar 3, 2021
@wilkinsona wilkinsona closed this in 14948cb Mar 3, 2021
@wilkinsona wilkinsona modified the milestones: 2.3.x, 2.3.10 Mar 3, 2021
@wilkinsona
Copy link
Member

This is beautiful, Christoph. Thanks very much.

@wilkinsona
Copy link
Member

Unfortunately, this has made Windows grumpy. I think the problem, or at least part of the problem, is that the processes are still running when we attempt to clean up the jar files. I'm hopeful that destroying the processes and then clean up the temp dir will fix it.

@dreis2211
Copy link
Contributor Author

@wilkinsona I'm very sorry - I don't have a Windows machine anymore to test against :/

@wilkinsona
Copy link
Member

@dreis2211 A wise man once said to me not to worry about breaking some tests… Seriously, please don't worry about it. These things happen after all. I reviewed the changes and it didn't occur to me that it'd cause grief with Windows.

@dreis2211
Copy link
Contributor Author

I saw it's still failing...what about bypassing the cache on Windows as a last resort?

@wilkinsona
Copy link
Member

wilkinsona commented Mar 3, 2021

The Windows builds only run daily unless we trigger them manually so they hadn't run with my latest tweak. I've just triggered a 2.3.x Windows build 🤞.

@wilkinsona
Copy link
Member

The build passed with spring-boot-server-tests:test taking a little over 7 mins. They took 16 mins yesterday.

Thanks again for the changes, @dreis2211. That's a very welcome reduction in the build time.

@dreis2211
Copy link
Contributor Author

Thank you for tackling the Windows stuff 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: task A general task
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants